<template>
	<view class="box">
		<!-- 图片编辑 -->
		<imgEdit ref="imgEdit" @ok="saveImg" @close="toBack" />
	</view>
</template>

<script>
	import imgEdit from '@/components/image-edit/x-image-edit.vue'
	export default {
		components: {
			imgEdit
		},
		data() {
			return {
			}
		},
		onLoad({
			url
		}) {
			this.$nextTick(()=>{
				this.$refs.imgEdit.open(url)
			})
		},
		methods: {
			saveImg(url) {
				uni.showLoading({
					title:'加载中...'
				})
				// console.log(url)
				// this.$refs.imgEdit.close()
				let that = this
				uniCloud.uploadFile({
					filePath: url,
					cloudPath: 'a.jpg',
					success(res) {
						// console.log(res)
						uni.setStorage({
							key: 'image',
							data: {
								StagingData: {
									'image': {
										url: res.fileID,
										size: 123,
										name: 'xxxxx.png'
									}
								},
								isImage: true
							},
							success: function() {
								console.log('success', '-----------image');
								uni.hideLoading()
								uni.navigateBack()
								uni.hideLoading()
							}
						});
					},
					fail() {},
				});

			},
			toBack(){
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 100vw;
		height: 100vh;
		background-color: #000;
	}
</style>